<!--# layout("/common/mallout.html"){ -->
<style>
    .file_info_list a {
        color: #6647b2;
        text-decoration: underline;
        display: inline-block;
        width: 147px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: top;
    }
</style>
<link rel="stylesheet" href="http://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/style/cart.css">
<div style="display:none;" class="hiddenParam">
    <input type="hidden" id="fileId" value="">
    <input type="hidden" id="fileNum" value="">

</div>
<div class="center">

    <div class="good-cart">
        <div class="cart-steps">
            <span>购物车</span>
            <input type="hidden" id="cartTypes" >

        </div>
        <div class="cart-container">
            <table class="cart-main" id="cart-main">
                <thead>
                <tr>
                    <th class="check_td">
                        <label class="check_input" for="chkall"><i></i>全选</label>
                        <input type="checkbox" nam="chkall" id="chkall" class="choose_all">
                    </th>
                    <th style="width:40%">商品</th>
                    <th>单价</th>
                    <th>款式数量</th>
                    <th>小计</th>
                    <th>附件</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody style="border:none;">
                <tr>
                    <td colspan="7" style="padding:10px 0px;"></td>
                </tr>
                </tbody>
                <!--统一公司名称**********************************************-->
                <tr shop-id="2166" class="promotion" head="1">
                    <td colspan="7" class="check_td" style="text-align: left">
                        <label class="check_input choose_same  active" shop-id="2166" for="chkSame"><i></i></label>
                        <strong>中浩紫云</strong>
                    </td>
                </tr>
                <tr shop-id="2166" goods-id=""  data-cart-id="602" store="0" skuid="104280">
                    <td class="check_td">
                        <label class="check_input choose_one active" cart-id="602" shop-id="2166"><i></i></label>
                    </td>
                    <td>
                        <div class="p-pic">
                            <a href="/mall/skuProductDetails.do?goodsId=13814&amp;goodsType=standard" target="_blank">
                                <img src="https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/image/pic_pop_05.png">
                            </a>
                        </div>
                        <div class="goods_name" style="padding-left: 70px;box-sizing: border-box">
                            <p><strong> 名片 </strong></p>
                            <p>标准商品</p>
                            <p>产品尺寸 : 90x54mm(常规尺寸)、表面工艺 : 覆膜、印刷盒数 : 1盒</p>
                        </div>
                    </td>
                    <td> <strong>￥15</strong></td>
                    <td class="number">

                        <p><span class="num_sub">-</span><input type="text" data-stock="" data-value="2" goodstype="standard" value="2"><span class="num_add">+</span> </p>

                    </td>
                    <td>
                        <strong class="price">￥<font style="font-size:18px;">30</font></strong>
                    </td>
                    <td class="" appendid="" data-cart-id="602" style="position: relative;">
                        <div class="action-uploadFile" id="uploadFile602" order_num="1" style="position: relative; z-index: 1;cursor: pointer;">上传附件</div>

                        <span style="/*position: relative;margin-left: 51px;*/">
                            <span class="file_info_list 602_picture" style="position: absolute;left: 0px;right: 0px;height: 30px;width: 185px;display: inline-block;vertical-align: middle;overflow: hidden;">


                            </span>
                        </span>
                        <input type="hidden" >

                        <span style="margin-left: 180px;cursor: pointer;display:none;" class="602_moreFile">↓</span>
                        <div id="html5_1cqcn6cf81a2h13r91ubl52r19kfc_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: 60px; left: 0px; width: 148px; height: 19px; overflow: hidden; z-index: 0;"><input id="html5_1cqcn6cf81a2h13r91ubl52r19kfc" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="image/jpeg,image/png,image/gif,image/photoshop,application/postscript,.cdr,application/vnd.ms-powerpoint,.word,.excel,application/pdf,image/tiff,.rar,application/zip,.7z"></div></td>
                    <td class="operation">
                        <i></i>
                        <a class="del_cart_good" cart-id="602" shop-id="2166" flag="one" href="javascript:void(0)">移除</a>
                    </td>
                </tr>


                </tbody><tbody style="border:none;" balck="black">
            <tr>
                <td colspan="6" style="padding:10px 0px;"></td>
            </tr>
            </tbody>
            </table>
        </div>
        <div class="order_main_price">
            <div class="order_main_price_01">
                <div class="account-select check_td">
                    <label class="check_input" for="chkall"><i></i><input id="chkall" type="checkbox" nam="chkall" class="choose_all">全选</label>
                    <span class="del_cart_good" style="margin-left:11px" flag="all">删除所选商品</span>
                </div>
                <div class="account-price">
                    <p>总价：<strong class="price">￥<font class="zongjia">30</font></strong></p>
                </div>
                <div class="account-price">
                    <p>已省：￥<span class="discount_price price">0</span></p>
                </div>
                <div class="account-number">
                    已选择 <i class="pic  cart_num"><strong class="price">1</strong></i> 件商品
                </div>

            </div>
        </div>

        <div class="submit-order">
            <button class="action-submit-order" id="balanceCart">提交订单</button>
        </div>
    </div>

    
</div>

<script id="loadCart" type="text/html">
    <div class="good-cart">
        <div class="cart-steps">
            <span>购物车</span>
            <input type="hidden" id="cartTypes" value="">

        </div>
        <div class="cart-container">
            <table class="cart-main" id="cart-main">
                <thead>
                <tr>
                    <th class="check_td">
                        <label class="check_input  {{totalQuantity == totalSum? 'active' : ''}}" for="chkall"><i></i>全选</label>
                        <input type="checkbox" nam="chkall" id="chkall" class="choose_all">
                    </th>
                    <th style="width:38%">商品</th>
                    <th style="width: 1px;">单价</th>
                    <th>款式数量</th>
                    <th>小计</th>
                    <th style="width: 75px;">&nbsp;&nbsp;</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody style="border:none;">
                <tr>
                    <td colspan="7" style="padding:10px 0px;"></td>
                </tr>
                </tbody>

                <input type="hidden" {{cartNum = 1}} >
                {{each cartShopVOList as cartInfo i }}
                <input type="hidden" {{headNum = 0 }}  {{singleNum = 0}} >
                <tbody>

                {{each cartInfo['cartItemVOList'] as cart}}
                <input type="hidden" {{headNum++}}>
                {{if cart['choice'] == true }}
                <input type="hidden" {{singleNum++}}>
                {{/if}}
                {{/each}}
                <!--统一公司名称**********************************************-->
                <tr shop-id="{{cartInfo['shopId']}}" class="promotion" head="{{headNum}}">
                    <td colspan="7" class="check_td" style="text-align: left">
                        <label  class="check_input choose_same  {{headNum==singleNum? 'active':''}}" shop-id="{{cartInfo['shopId']}}" for="chkSame"><i></i></label>
                        <strong >{{cartInfo['shopName']}}</strong>
                    </td>
                </tr>

                {{each cartInfo['cartItemVOList'] as cartItem i}}
                <tr shop-id="{{cartItem['shopId']}}"  goods-id=""   data-cart-id="{{cartItem['cartId']}}" store="{{cartItem['store']}}" skuId="{{cartItem['id']}}">
                    <td class="check_td">
                        <label  class="check_input choose_one  {{cartItem['invalid'] == true ? 'invalid' : cartItem['choice']== true ? 'active' : ''}} " cart-id="{{cartItem['cartId']}}" shop-id="{{cartItem['shopId']}}"><i></i></label>
                    </td>
                    <td>
                        <div class="p-pic">
                            {{if cartItem['invalid'] == true}}
                            <a href="javascript:;">
                                <img src="${imagepath}/{{cartItem['imgUrl']}}">
                                <div class="sold_out">
                                    已下架
                                </div>
                            </a>
                            {{else}}
                            <a href="/mall/skuProductDetails.do?goodsId={{cartItem['spuId']}}&goodsType={{cartItem['goodsType']}}" target="_blank">
                                {{if cartItem['imgUrl'] == null || cartItem['imgUrl'] == ''}}
                                <img src="${imagepath}/pop/mall/image/pic_pop_02.png">
                                {{else}}
                                <img src="${imagepath}/{{cartItem['imgUrl']}}">
                                {{/if}}
                            </a>
                            {{/if}}
                        </div>
                        <div class="goods_name" style="padding-left: 50px;box-sizing: border-box">

                            <p><strong> {{cartItem['name']}} </strong></p>
                            <p>{{ cartItem['goodsType'] | getType }}</p>
                            <p>{{cartItem['attributeOptionNameStr']}}</p>
                            {{if cartItem['goodsType'] == 'paper' || cartItem['goodsType'] == 'material'}}
                            <p>
                                {{if cartItem['paperLength']}}
                                    长度:{{cartItem['paperLength']}}
                                {{/if}}
                                {{if cartItem['paperLength']}}
                                    宽度:{{cartItem['paperWidth']}}
                                {{/if}}
                            </p>
                            {{/if}}
                            {{if cartItem['goodsType'] == 'design'}}
                            <p>{{cartItem['designDesc']}}</p>
                            {{/if}}
                        </div>
                    </td>
                    <td> <strong>￥{{cartItem['price']}}</strong></td>
                    <td class="number">
                        {{if cartItem['overlying'] == false || cartItem['invalid'] == true }}
                        <input type="text" data-stock="" data-value="{{cartItem['quantity']}}" value="{{cartItem['quantity']}}">
                        {{else}}
                        <p><span class="num_sub">-</span><input type="text" data-stock="" data-value="{{cartItem['quantity']}}" minBuy="{{cartItem['shoppingMinimum']}}"  maxBuy="{{cartItem['shoppingMaxmum']}}" goodsType="{{cartItem['goodsType']}}" value="{{cartItem['quantity']}}"><span class="num_add">+</span> </p>
                        {{/if}}
                    </td>
                    <td>
                        <strong class="price">￥<font style="font-size:18px;">{{cartItem['totalPrice']}}</font></strong>
                    </td>
                    <td class="" appendId="{{cartItem['appendId']}}" data-cart-id="{{cartItem['cartId']}}">
                        {{if cartItem['canUploadFile']}}
                        <div class="action-uploadFile" id="uploadFile{{cartItem['cartId']}}" order_num="{{cartNum++}}" style="position: relative; z-index: 1;cursor: pointer;">上传附件</div>
                        {{/if}}

                        <span style="/*position: relative;margin-left: 51px;*/">
                            <span class="file_info_list {{cartItem['cartId']}}_picture" style="position: absolute;left: 0px;right: 0px;height: 30px;width: 185px;display: inline-block;vertical-align: middle;overflow: hidden;">
                              {{if cartItem['accessoryVOList']!=null && cartItem['accessoryVOList'].length>1 }}
                                <input type="hidden" {{more = 1}} >
                                {{/if}}
                                {{ each cartItem['accessoryVOList'] as append i}}
                                 <em style="margin-left: -30px;">
                                <a href="javascript:" style="text-decoration:none;color: #6647b2;display: inline-block;width: 100px;height:34px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;vertical-align: top;">{{append['name']}}</a>
                                <i class="del" style="margin-top: 5px;;display: inline-block;width: 15px;height: 15px;cursor: pointer; margin-left: 15px; color: #f16c6c; line-height: 15px;text-align: center;" aid="{{append['id']}}">X</i>
                                </em>
                                 {{/each}}
                            </span>
                        </span>
                        <input type="hidden" {{flag = 0}} >
                        {{if cartItem['accessoryVOList']!=null && cartItem['accessoryVOList'].length>1 }}
                        <input type="hidden" {{flag = 1}} >
                        {{/if}}
                        <!--<span style="margin-left: 180px;cursor: pointer;{{flag == 1 ? '' : 'display:none'}};" class="{{cartItem['cartId']}}_moreFile moreFile" cartId = "{{cartItem['cartId']}}"><b>更多</b></span>-->
                    </td>
                    <td class="operation">
                        <i></i>
                        <a class="del_cart_good" cart-id="{{cartItem['cartId']}}" shop-id="{{cartItem['shopId']}}" flag="one" href="javascript:void(0)">移除</a>
                    </td>
                </tr>
                {{/each}}

                <tbody style="border:none;" balck="black">
                <tr>
                    <td colspan="6" style="padding:10px 0px;"></td>
                </tr>
                </tbody>

                </tbody>
                {{/each}}

            </table>
        </div>
        <div class="order_main_price">
            <div class="order_main_price_01">
                <div class="account-select check_td" >
                    <label  class="check_input {{totalQuantity == totalSum ? 'active':''}}" for="chkall" ><i></i><input id="chkall" type="checkbox" nam="chkall" class="choose_all">全选</label>
                    <span class="del_cart_good" style="margin-left:11px" flag="all">删除所选商品</span>
                </div>
                <div class="account-price">
                    <p>总价：<strong class="price">￥<font class="zongjia">{{totalPrice}}</font></strong></p>
                </div>
                <div class="account-price">
                    <p>已省：￥<span class="discount_price price">{{promotionPrice}}</span></p>
                </div>
                <div class="account-number">
                    已选择 <i class="pic  cart_num"><strong class="price">{{totalSum}}</strong></i> 件商品
                </div>

            </div>
        </div>

        <div class="submit-order">
            <button class="action-submit-order" id="balanceCart">提交订单</button>
        </div>
    </div>

</script>

<!--#} -->

<script>
layui.use(['index','laypage','element'], function(){
    var quoteCountPriceIndex = layui.index;
    quoteCountPriceIndex.init();
});

var click_rest_time = 500;//点击间隔时间（ms）
var click_state = true;   //点击状态

    var array=[];
doAjax("toLoadCart.json","post",{},function (ret) {
    if(ret.code == 1){
        var cartInfoVo = ret.data;
        var html = template('loadCart', cartInfoVo);
        $("div.center").html(html);
        $("#cartTypes").val(JSON.stringify(cartInfoVo.cartTypes));
        $(".action-uploadFile").each(function () {
            array.push($(this).attr("id"));
        });
        uploadFile(array);
    }else {
            var gouwuche = "<div style=\"height:335px; background:url('https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/image/pic_pop_05.png') center center no-repeat; text-align:center;  font-size:22px; color:rgb(208,208,208);overflow:hidden;\"><p style=\"margin-top:250px;\">购物车空空的哦~</p><p><a href='/index.do' style=\"font-size:18px; margin-top:20px; text-decoration:none; color:rgb(108,81,180)\"><strong>去添加心仪商品></strong></a></p></div>";
            $("div.center").html(gouwuche);
    }


});

//判断商品类型
template.defaults.imports.getType = function(value){
    var type_arr = {};
    type_arr['standard'] = '标准商品';
    type_arr['fast'] = '快印商品';
    type_arr['material'] = '广告物料';
    type_arr['print'] = '印刷商品';
    type_arr['paper'] = '大纸类商品';
    type_arr['design'] = '设计商品';
    type_arr['copy'] = '复印纸商品';
    type_arr['material'] = '广告物料';

    return type_arr[value];

};

//商品勾选操作
function chooseAll(){
    var allCartNum =0;//所有购物车数量
    $("tr[head]").each(function () {
        allCartNum += parseInt($(this).attr('head'));
    });
    if($("label.choose_one.active").length == allCartNum){
        $("label.check_input[for=chkall]").addClass("active");
    }else{
        $("label.check_input[for=chkall]").removeClass("active");
    }
}

$(document).on('click','.check_input',function () {
    var acvtive = $(this).hasClass('active');  //判断其是否勾选
            var param = {};
    if($(this).attr('for') == 'chkall'){   //如果是全选
        if(!acvtive){
            $(this).addClass('active');
            $("label.check_input").not(".invalid").addClass('active');

            param['status'] = true;
            cartSendAjax("/cart/selectCartAll.json","post",{"param":JSON.stringify(param)});
        }else{
            $(this).removeClass("active");
            $("label.check_input").not(".invalid").removeClass('active');
            param['status'] = false;
            cartSendAjax("/cart/selectCartAll.json","post",{"param":JSON.stringify(param)});
        }
    }else if($(this).attr('for') == 'chkSame'){   //如果是相同类型选择
        var shopId = $(this).attr('shop-id');
        var ids = "";
        var len=$(this).parents("tbody").find('tr').length;
        if(!acvtive){
            $(this).addClass('active');

            $("label.choose_one").each(function () {
                if($(this).attr('shop-id') == shopId){
                    if(!$(this).hasClass("invalid")){
                        $(this).addClass('active');
                        ids += $(this).attr('cart-id')+",";
                    }

                }
            });
            ids = ids.substr(0,ids.length-1);
            param['cartIdsStr'] = ids;
            chooseAll();

            cartSendAjax("/cart/selectCart.json","post",{"param":JSON.stringify(param)});
        }else{
            $(this).removeClass("active");

            $("label.choose_one").each(function () {
                if($(this).attr('shop-id') == shopId){
                    if(!$(this).hasClass("invalid")){
                        $(this).removeClass('active');
                        ids += $(this).attr('cart-id')+",";
                    }
                }
            });
            ids = ids.substr(0,ids.length-1);
            chooseAll();
            param['cartIdsStr'] = ids;
            cartSendAjax("/cart/cancelCart.json","post",{"param":JSON.stringify(param)})
        }
    }else{     //单选 //找到当前tr头数据
        var headNum = $($(this).parents("tr").siblings("tr[head]").get(0)).attr('head');
       if($(this).hasClass("invalid")) return;
        if(!acvtive){ //如果勾选

            $(this).addClass('active');
            var activeNum = $(this).parents("tbody").find("label.active").length;
            if( activeNum==headNum ){
                $($(this).parents("tr").siblings("tr[head]").get(0)).find("label.check_input").addClass('active');
            }
            chooseAll();
            param['cartIdsStr'] = $(this).attr('cart-id');
            cartSendAjax("/cart/selectCart.json","post",{"param":JSON.stringify(param)});
        }else{
            $(this).removeClass("active");
            var activeNum = $(this).parents("tbody").find("label.active").length-1;
            if(headNum!=activeNum){
                $($(this).parents("tr").siblings("tr[head]").get(0)).find("label.check_input").removeClass('active');
            }
            chooseAll();
            param['cartIdsStr'] = $(this).attr('cart-id');
            cartSendAjax("/cart/cancelCart.json","post",{"param":JSON.stringify(param)});
        }
    }
});


//移除商品
$(document).on('click','.del_cart_good',function () {
    var param = {};
    var ids = "";
    var flag = $(this).attr('flag');

    if(flag == 'one'){
        ids = $(this).attr('cart-id');

        //单个移除商品
        var len=$(this).parents("tbody").find('tr').length;

        if(len<=2)
        {
            $(this).parents("tbody").next('tbody').remove();
            $(this).parents("tbody").remove();
        }
        else{
            $(this).parents("tr").remove();
        }

        param['cartIdsStr'] = ids
        cartSendAjax("/cart/deleteItem.json",'post',{"param":JSON.stringify(param)});

    }else if(flag == 'all'){
        $("label.choose_one").each(function () {
            if($(this).hasClass('active')){
                ids += $(this).attr('cart-id')+",";
            }
        });
        ids =  ids.substr(0,ids.length-1);

        //删除所选
        $("label.check_input.active").each(function (i,o) {
            $(o).parents("tr[shop-id]").remove();
        })
            param['cartIdsStr'] = ids
            cartSendAjax("/cart/deleteItem.json",'post',{"param":JSON.stringify(param)});
    }
})

//去结算
$(document).on('click','#balanceCart',function(){
    var $one = $('.choose_one');
    var oneNum = 0;
    $one.each(function(){
        if($(this).hasClass('active')){
            oneNum= oneNum+1;
        }
    });
    if(oneNum==0){
        $.alert("error","当前没有可以结算的商品",1);
        return;
    }
    var  cartTypes = $.parseJSON($("#cartTypes").val());
    var multNum = 0;
    var key = "";
    for( key in cartTypes){
        multNum++;
    }
    if(multNum>=2){
        $.alert("error","请分类型结算不同商品",1);
        return;
    }
        window.location.href = "/order/popGoDown/gwcIndex.do?cartType="+key;

});


//减少数量
$(document).on('click','.cart-main .num_sub',function () {
    if(!click_state)return;
    setTimeout(function(){
        click_state = true;
    },click_rest_time)
    var input_obj = $(this).siblings('input');

    var cur_val = Number(input_obj.val());
    var store = $(this).parents("tr").attr('store');
    if(cur_val  <=1 )return;

    click_state = false;
    CountAnim(this,cur_val+'',(cur_val-1)+'',-22);
    input_obj.val(Number(cur_val-1));

    var cartId = $(this).parents('tr').attr('data-cart-id');
    var skuId = $(this).parents('tr').attr('skuId');
    var param = {};
    param['cartId'] = cartId;
    param['countNum'] = input_obj.val();
   // param['store'] = store;
    param['skuId'] = skuId;

    num_change({"param":JSON.stringify(param)});
})



//增加数量
$(document).on('click','.cart-main .num_add',function () {
    if(!click_state)return;
    setTimeout(function(){
        click_state = true;
    },click_rest_time)
    var input_obj = $(this).siblings('input');
    var cur_val = Number(input_obj.val());
    var stock_val = Number($(this).siblings('input').attr('data-stock'));
    var store = $(this).parents("tr").attr('store');

    if(cur_val+1 >= 99999){
        $.alert('error','超出最大数额');
        input_obj.val(input_obj.attr('data-value'));
        return;
    }

    click_state = false;
    CountAnim(this,cur_val+'',(cur_val+1)+'',-22);
    input_obj.val(Number(cur_val+1));

    var cartId = $(this).parents('tr').attr('data-cart-id');
    var skuId = $(this).parents('tr').attr('skuId');
    var param = {};
    param['cartId'] = cartId;
    param['countNum'] = input_obj.val();
    //param['store'] = store;
    param['skuId'] = skuId;

    num_change({"param":JSON.stringify(param)});
})


//手动输入数量
$(document).on('blur','.cart-main .number p input',function () {
    var cur_num = $(this).val();
    var minBuy = $(this).attr("minBuy");
    var buyCount = $(this).attr("data-value");
    if(isNaN(cur_num)){
        $(this).val(buyCount);return;
    }else if(cur_num<=0){
        $(this).val(buyCount);
        cur_num = buyCount;
    }

    var cartId =  $(this).parents('tr').attr('data-cart-id');
    var skuId =  $(this).parents('tr').attr('skuId');
    var stock_val = Number($(this).attr('data-stock'));
    var store = $(this).parents("tr").attr('store');
    if(cur_num > 99999){
        $.alert('error','超出最大数额');
        $(this).val($(this).attr('data-value'));
        return;
    }

    var change_num = Number(cur_num) - Number($(this).attr('data-value'));
    if(change_num == 0){
        return;
    }
    cur_num  = new Number(cur_num).toFixed(6);
    var param = {};
    param['cartId'] = cartId;
    param['countNum'] = cur_num;
    //param['store'] = store;
    param['skuId'] =skuId;

    num_change({"param":JSON.stringify(param)});
})

//数量变化请求
    function num_change(param){
         cartSendAjax("/cart/changeNum.json","post",param);
    }


//数字动画效果
var CountAnim=function(obj,j,l,num){
    var txtCount = $(obj).siblings("input");
    var p=$(obj).parent();
    var k='';
    var j=j.split('');
    txtCount.css('color','#fff');
    for (var s = 0; s < j.length; s++)
    {
        k += '<i style="position:relative;">' + j[s] + "</i>";
    }
    p.prepend('<i class="upspan" >' + k + "</i>");

    var m='';
    var l=l.split('');
    for (var n = 0; n <l.length; n++)
    {
        m += '<i style="position:relative;">' + l[n] + '</i>';

    }
    p.append('<i class="downspan" style="top:'+(-num)+'px;">' + m + "</i>");
    var d = $(".downspan i:last");
    var u= $(".upspan i:last");

    u.animate({top: num}, "10");
    d.animate({top: num}, "10",function(){
        $('.downspan,.upspan').remove();
        txtCount.css('color','#333');
    });
}

//购物车发送ajax
function cartSendAjax(url,type,param){
    doAjax(url,"post",param,function(ret){
        if(ret.code == 1){
            var cartInfoVo = ret.data;
            var html = template('loadCart', cartInfoVo);
            $("div.center").html('');
            $("div.center").html(html);
            $("#cartTypes").val(JSON.stringify(cartInfoVo.cartTypes));
            var array=[];
            $(".action-uploadFile").each(function () {
                array.push($(this).attr("id"));
            });
            uploadFile(array);
        }else if(ret.code == 1401){
            var gouwuche = "<div style=\"height:335px; background:url('https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/pop/mall/image/pic_pop_05.png') center center no-repeat; text-align:center;  font-size:22px; color:rgb(208,208,208);overflow:hidden;\"><p style=\"margin-top:250px;\">购物车空空</p><p><a href='/index.do' style=\"font-size:18px; margin-top:20px; text-decoration:none; color:rgb(108,81,180)\"><strong>去添加心仪商品></strong></a></p></div>";
            $("div.center").html(gouwuche);

        }else{
            $.alert('error',ret.message,1);
            doAjax("toLoadCart.json","post",{},function (ret) {
                var cartInfoVo = ret.data;
                var html = template('loadCart', cartInfoVo);
                $("div.center").html(html);
                var array=[];
                $(".action-uploadFile").each(function () {
                    array.push($(this).attr("id"));
                });
                uploadFile(array);
            });
        }
    });
}

function reload(){
    setTimeout(function(){
        location.href = location.href;
    },1000);
}
</script>

<script>
    //上传附件
    var fileIdList=[];
    var i = 0;
    function uploadFile(array){
        $.files_up_oss({
            id: array, //按钮id
            url: "/oss/getSignatureNew",
            dir: "order/orderImage/",
            file_type: "jpg,png,gif,psd,ai,cdr,eps,ppt,word,excel,pdf,tiff,rar,zip,7z,gif",
            size: "100mb",//mb
            view_url: "https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/"
        },function(index_number,json){
               var cartId =  $("tr[data-cart-id]").eq(index_number).attr('data-cart-id');
            if (json.Status == 'OK') {
                $("#fileNum").val(json.total);
                var requestData={
                    url:json.filename,
                    name:json.filename,
                    size:json.size,
                    type:json.mimeType,
                    uniqueId:(new Date()).valueOf()
                }
                doAjax("/user/userAccessory/addAccessory.json", 'post', {'requestData':JSON.stringify(requestData)}, function(ret){
                i++;
                    var fileId=ret.data.resultDtos[0].id;
                    fileIdList.push(fileId);//成功后将附件id放入集合 <span class="del">删除</span>
                    var html = "<em class='fileEm' style='margin-left: -30px;'>\n" +
                        "<a href=\"javascript:\" style=\"text-decoration:none;color: #6647b2;display: inline-block;width: 100px;height:34px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;vertical-align: top;\">"+json.filename+"</a>\n" +
                        "<i class=\"del\" style=\"margin-top: 5px;;display: inline-block;width: 15px;height: 15px;cursor: pointer; margin-left: 15px; color: #f16c6c; line-height: 15px;text-align: center;\" aid="+fileId+">X</i>\n" +
                        "</em>";
                    $("."+cartId+"_picture").append(html);
                    if(i ==  $("#fileNum").val()){
                        var cartAppendParam = {};
                        cartAppendParam['cartId'] = cartId;
                        cartAppendParam['appendIds'] = fileIdList;
                        //一起将返回的附件id插入 一条 购物车记录
                        doAjax("/cart/addAppend.json","post",{"param":JSON.stringify(cartAppendParam)},function (ret) {
                            if(ret.code == 1){
                                $.alert("succes","上传成功",1);
                            }
                        })
                    }
                    // if(json.total>1){
                    //     $("."+cartId+"_moreFile").show();
                    // }

                });
            }

        })
    }

    //删除附件
    $(document).on('click',"i.del",function () {
        var obj = $(this);
        var aid = $(this).attr('aid');
        var cartId = $(this).parents("tr").attr('data-cart-id');
        var cartAppendParam = {};
        var appendIds = [];
        appendIds.push(aid);
        cartAppendParam['cartId'] = cartId;
        cartAppendParam['appendIds'] = appendIds ;
        doAjax("/cart/delAppend.json","post",{"param":JSON.stringify(cartAppendParam)},function (ret) {
            if(ret.code == 1){
                obj.parent().remove();
                // if($("em.fileEm").length<2){
                //     $("span.moreFile").hide();
                // }
            }else{
                $.alert("error","删除失败",1);
            }
        });
    });

    //点击更多
    // var flag = true;
    // $(document).on("click","span.moreFile",function () {
    //     var cartId = $(this).attr("cartId");
    //     if(flag){
    //         flag = false;
    //         $("span."+cartId+"_picture").css("height","auto");
    //     }else{
    //         flag = true;
    //         $("span."+cartId+"_picture").css("height","30px");
    //     }
    // })

</script>

